package Fragment

import android.annotation.SuppressLint
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import com.example.hospitalmanagementapp.R
import com.lljjcoder.Interface.OnCityItemClickListener
import com.lljjcoder.bean.CityBean
import com.lljjcoder.bean.DistrictBean
import com.lljjcoder.bean.ProvinceBean
import kotlinx.android.synthetic.main.fragment_new_born.*
import kotlinx.android.synthetic.main.fragment_people__child.*
import util.DocumentTypeUtil
import util.RegionalSelectedUtil
import util.TimeSelectedUtil


class NewBornFragment (context: Context): Fragment() {
    private val context1: Context =context
    var  array= arrayOf("身份证","护照","港澳居民来往内地通行证",
        "台湾居民来往内地通行证","外国人永久居留身份证","中华人民共和国出入境通行证","中华人民共和国旅行证")
    private var mPopupWindow = PopupWindow()
    private val timeSelectedUtil= TimeSelectedUtil(context)
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_new_born, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    private fun initView() {
        //日期选择实现
        val pickerView=timeSelectedUtil.timeSelected()
        new_born_date.setOnClickListener {
            pickerView.show(new_born_date)
        }
        //省市县选择实现
        // 初始化城市选择器
        new_born_regional.setOnClickListener {
            var cityPickerView = RegionalSelectedUtil(context1).regionalSelect()
            cityPickerView.setOnCityItemClickListener(object : OnCityItemClickListener() {
                @SuppressLint("SetTextI18n")
                override fun onSelected(
                    province: ProvinceBean,
                    city: CityBean,
                    district: DistrictBean
                ) {
                    super.onSelected(province, city, district);
                    new_born_regional.setText(
                        province.toString().trim()  + city.toString()
                            .trim()  + district.toString().trim()
                    );
                }
            })
        }
        //监护人身份证类型功能实现
        new_born_category.setOnClickListener {
            //身份证功能实现
            var documentSelect= DocumentTypeUtil(context1).documentType()
            documentSelect.setItems(array, DialogInterface.OnClickListener { dialog, which ->
                new_born_category.setText(array[which])
            })
        }
    }
}